home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DEV / A-B / add images.cpt / image_add_proto.c < prev    next >
Text File  |  1989-06-22  |  9KB  |  362 lines

  1.  
  2. /* --- This source is for Lightspeed C 3.0 or greater --- */
  3.  
  4. /*     image_add_proto.c      Main program   */
  5.  
  6. /*     InitTheMenus   initializes the menus */
  7. /*     about_alert    Alerts */
  8. /*     Source_2       Window */
  9. /*     Source_1       Window */
  10. /*     Result         Window */
  11. /*     HandleTheMenus Handle the menu selection */
  12.  
  13. /* Resource file to use is  image_add_proto.RSRC  */
  14. /* RMaker file to use is image_add_proto.R   */
  15.  
  16. /* MacTraps        use this LSC library from the    Mac Libraries    fol*/
  17. /* strings         use this LSC library from the    Libraries    folder */
  18.  
  19.  
  20. /* ==============================
  21.  
  22. Program name:  image_add_proto.c
  23. Function:  This is the main module for this program.
  24. History: 4/27/89 Original by Prototyper.
  25.  
  26. ================================= */
  27.  
  28. /* *********************************** */
  29. /* These are the other includes for general routines */
  30.  
  31. #include <Strings.h>
  32. extern char *strcpy (Str255 *, char *);    /* LSC string prototype */
  33.  
  34. /* *********************************** */
  35.  
  36. #define      TRUE   1
  37. #define      FALSE  0
  38. #define      NIL    0
  39.  
  40. /* *********************************** */
  41.  
  42. /* External routines that are called */
  43.  
  44. extern void InitMyMenus (void);
  45.  
  46. /* #include <color.h> */
  47. /* #include <colortoolbox.h> */
  48. #include <IM1_5Protos.h>
  49.  
  50. #include "about_alert.h"
  51. #include "Source_2.h"
  52. #include "Source_1.h"
  53. #include "Result.h"
  54. #include "HandleTheMenus.h"
  55. #include "initclut.h"
  56.  
  57. extern WindowPtr Result_Window;
  58. extern WindowPtr proton_Window;
  59. extern WindowPtr flourine_Window;
  60.  
  61. extern MenuHandle AppleMenu;
  62. extern MenuHandle FileMenu;
  63. extern MenuHandle EditMenu;
  64. extern MenuHandle ModeMenu;
  65.  
  66. /* global variables */
  67.  
  68. short pix_zoom;
  69. short clipboard_empty;
  70. short add_mode;
  71. Rect dragRect;
  72.  
  73.  
  74. /* ====================================== */
  75. void main (void);            /* Prototype for the main module */
  76. /* ====================================== */
  77.  
  78.  
  79. void main ()
  80. {
  81.     char doneFlag;            /* Exit program flag */
  82.     char Is_A_Dialog;        /* Flag to check for Dialog inputs */
  83.     char stillInGoAway;
  84.     char ch;                /* Key pressed in Ascii */
  85.     short code;                /* Determine event type */
  86.     short theMenu, theItem;    /* Menu list and item selected */
  87.     short chCode;            /* Key code */
  88.     long mResult;            /* Menu list and item selected values */
  89.     WindowPtr whichWindow;    /* See which window for event */
  90.     WindowPtr tempWindow;
  91.     EventRecord myEvent;    /* Event record for all events */
  92.     TEHandle theInput;
  93.     Point myPt;                /* Temp Point, used in Zoom */
  94.  
  95.     GrafPtr SavePort;        /* Place to save the current drawing port */
  96.  
  97.     long scrap_offset;      /* holds offset of an item in the scrap/clipboard */
  98.     WindowPtr Current_Window;    /* lets us know when DA is in front */
  99.  
  100.     Point mousepos;     /* current mouse position */
  101.     char mouse_h[255], mouse_v[255];
  102.     Rect er, r;
  103.  
  104.     static int draw_pos;
  105.     
  106. /* ---------------------------------------------------------------------- */
  107.  
  108.     InitGraf ( (Ptr) &thePort);
  109.     InitFonts ();
  110.     FlushEvents (everyEvent, 0);
  111.     InitWindows ();
  112.  
  113.     InitMenus ();
  114.     TEInit ();
  115.     InitDialogs (NIL);
  116.     InitCursor ();            /* Start with a visible arrow cursor  */
  117.  
  118.     MoreMasters();
  119.     MoreMasters();
  120.     MoreMasters();
  121.     MaxApplZone();
  122.     
  123.     OpenResFile ( "\pimage_add_proto.RSRC" );    /* **** Open our resource fi*/
  124.  
  125.     doneFlag = FALSE;        /* Do not exit program yet */
  126.  
  127.     dragRect = screenBits.bounds;
  128.     dragRect.top -= MBarHeight;
  129.  
  130.     InitMyMenus ();
  131.  
  132.     theInput = NIL;
  133.  
  134.     Init_gray_clut();
  135.     
  136.     Init_proton ();
  137.     Open_proton ();
  138.     init_clut_proton();
  139.  
  140.     Init_flourine ();
  141.     Open_flourine ();
  142.     init_clut_flourine();
  143.  
  144.     Init_Result ();
  145.     Open_Result ();
  146.     init_clut_result();
  147.  
  148.     pix_zoom = 2;     /*     initial pixel-zoom value  2/2 = 1,
  149.                         zooming goes from 1/2 = 0.5 to 2/2 = 1 to
  150.                         4/2 = 2, to 8/2 = 4 */
  151.  
  152.     Current_Window = NIL;
  153.  
  154.     draw_pos = 50;
  155.  
  156.     do                        /* Start of main event loop */
  157.     {
  158.         SystemTask ();
  159.  
  160. /*
  161.     disable, enable menus -- find out if clipboard has a PICT or should be considered empty
  162.     (may want to use ScrapInfo to minimize overhead.)
  163. */
  164.  
  165.         if ( GetScrap (NIL, 'PICT', &scrap_offset) == noTypeErr  )
  166.         {
  167.             clipboard_empty = TRUE;
  168.         }
  169.         else
  170.         {
  171.             clipboard_empty = FALSE;
  172.         }
  173.  
  174.         if ( Current_Window != FrontWindow() )
  175.         {
  176.             Current_Window = FrontWindow();
  177.             Update_Menus( Current_Window );
  178.             DrawMenuBar(); /* handle dimming of entire menus */
  179.         }
  180.         else
  181.         {
  182.             Update_Menus( Current_Window ); /* dimming of menu items */
  183.         }
  184.  
  185.         if (GetNextEvent (everyEvent, &myEvent))
  186.         {
  187.             code = FindWindow (myEvent.where, &whichWindow);
  188.  
  189.             switch (myEvent.what)
  190.             {
  191.             case mouseDown:
  192.                 if (code == inMenuBar)
  193.                 {
  194.                     mResult = MenuSelect (myEvent.where);
  195.                     theMenu = HiWord (mResult);
  196.                     theItem = LoWord (mResult);
  197.                     HandleMenu (&doneFlag, theMenu, theItem, &theInput);
  198.                 }
  199.  
  200.                 if ((code == inDrag) && (whichWindow != NIL))
  201.                 {
  202.                     if ( (myEvent.modifiers & cmdKey == 0) && (whichWindow != FrontWindow()) )
  203.                     {
  204.                         SelectWindow( whichWindow );
  205.                     } /* if commandkey is down, then user can drag a un-selected window */
  206.                     else
  207.                     {
  208.                         DragWindow (whichWindow, myEvent.where, &dragRect);
  209.                     }
  210.                 }
  211.  
  212.                 if (code == inGrow)
  213.                 {
  214.  
  215.                     switch (GetWRefCon (whichWindow))
  216.                     {
  217.                         case 9:
  218.                             grow_flourine (&myEvent.where, whichWindow);
  219.                             break;
  220.                         case 8:
  221.                             grow_proton (&myEvent.where, whichWindow);
  222.                             break;
  223.                         case 10:
  224.                             grow_result (&myEvent.where, whichWindow);
  225.                             break;
  226.                     }
  227.  
  228.                 }
  229.  
  230.                 /* if (code == inGoAway) -- we don't have go-away boxes in our windows */
  231.  
  232.                 if (code == inContent)
  233.                 {
  234.                     if (whichWindow != FrontWindow ())
  235.                     {
  236.                         SelectWindow (whichWindow);
  237.                     }
  238.                     else
  239.                     {
  240.                         switch (GetWRefCon (whichWindow))
  241.                         {
  242.                         case 9:
  243.                             Do_flourine (&myEvent);
  244.                             break;
  245.                         case 8:
  246.                             Do_proton (&myEvent);
  247.                             break;
  248.                         case 10:
  249.                             Do_Result (&myEvent);
  250.                             break;
  251.                         }
  252.                     }
  253.                 }
  254.  
  255.                 if (code == inSysWindow)    /* See if a DA selection */
  256.                 {        /* Let the OS do it */
  257.                     SystemClick (&myEvent, whichWindow);
  258.                 }
  259.  
  260.                 if ((code == inZoomIn) || (code == inZoomOut))
  261.                 {        /* Start zoom */
  262.                     if (whichWindow != NIL)
  263.                     {
  264.                         switch (GetWRefCon (whichWindow))
  265.                         {
  266.                             case 9:
  267.                                 zoom_flourine (&myEvent.where, (WindowPeek) whichWindow, code);
  268.                                 break;
  269.                             case 8:
  270.                                 zoom_proton (&myEvent.where, (WindowPeek)whichWindow, code);
  271.                                 break;
  272.                             case 10:
  273.                                 zoom_result (&myEvent.where, (WindowPeek) whichWindow, code);
  274.                                 break;
  275.                         }
  276.                     }
  277.                 }
  278.  
  279.                 break;        /* End of mouseDown */
  280.  
  281.             case keyDown:
  282.             case autoKey:
  283.                 ch = myEvent.message & charCodeMask;
  284.                 if (myEvent.modifiers & cmdKey)
  285.                 {
  286.                     mResult = MenuKey (ch);
  287.                     theMenu = HiWord (mResult);
  288.                     theItem = LoWord (mResult);
  289.                     if (theMenu != 0)
  290.                         HandleMenu (&doneFlag, theMenu, theItem, &theInput);
  291.                     if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))
  292.                         TECut (theInput);    /* Handle a Cut in a TE area*/
  293.                     if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))
  294.                         TECopy (theInput);    /* Handle a Copy in a TE are*/
  295.                     if (((ch == 'v') || (ch == 'V')) && (theInput != NIL))
  296.                         TEPaste (theInput);    /* Handle a Paste in a TE ar*/
  297.                 }
  298.                 else if (theInput != NIL)
  299.                     TEKey (ch, theInput);
  300.                 break;
  301.  
  302.             case updateEvt:
  303.                 whichWindow = (WindowPtr)myEvent.message;
  304.                 switch (GetWRefCon (whichWindow))
  305.                 {
  306.                     case 9:
  307.                         UpDate_flourine (whichWindow);
  308.                         break;
  309.                     case 8:
  310.                         UpDate_proton (whichWindow);
  311.                         break;
  312.                     case 10:
  313.                         UpDate_Result (whichWindow);
  314.                         break;
  315.                 }
  316.                 break;
  317.  
  318.             case diskEvt:    /*  Disk inserted event */
  319.                 if (HiWord (myEvent.message) != 0)
  320.                 {        /* due to unformatted diskette inserted */
  321.                     myEvent.where.h = ( (screenBits.bounds.right - screenBits.bounds.left) / 2)
  322.                         - (304 / 2);    /* Center horz */
  323.                     myEvent.where.v = ( (screenBits.bounds.bottom - screenBits.bounds.top) / 3)
  324.                         - (104 / 2);    /* Top 3ed vertically */
  325.                     InitCursor ();    /* Make sure it has an arrow cursor */
  326.                     theItem = DIBadMount (myEvent.where, myEvent.message);
  327.                 }
  328.                 break;        /* End of DiskEvt */
  329.  
  330.             case activateEvt:    /* Window activated event  - how about deactivate?? */
  331.                 whichWindow = (WindowPtr)myEvent.message;
  332.                 if ((whichWindow != NIL))
  333.                 {
  334.                     switch (GetWRefCon (whichWindow))
  335.                     {
  336.                         case 9:
  337.                             activate_flourine (whichWindow, myEvent.modifiers);
  338.                             break;
  339.                         case 8:
  340.                             activate_proton (whichWindow, myEvent.modifiers);
  341.                             break;
  342.                         case 10:
  343.                             activate_result (whichWindow, myEvent.modifiers);
  344.                             break;
  345.                     }
  346.                 }
  347.                 break;
  348.  
  349.  
  350.             default:
  351.                 break;
  352.  
  353.             }
  354.  
  355.         }
  356.     }
  357.     while (doneFlag == FALSE);
  358.  
  359. }
  360.  
  361. /* End of MAIN */
  362.